package com.bingo.controller;

import com.bingo.common.R;
import com.bingo.entity.Immunization;
import com.bingo.entity.Medication;
import com.bingo.entity.Meteorology;
import com.bingo.entity.dto.req.ReqForm;
import com.bingo.service.ImmunizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/immunization")
public class ImmunizationController {
    private ImmunizationService immunizationService;
    @Autowired
    public void setImmunizationService(ImmunizationService immunizationService) {
        this.immunizationService = immunizationService;
    }

    @PostMapping("/record")
    public R immunizationRecord(@RequestBody ReqForm reqForm) {
        return R.success(immunizationService.selectImmunizationRecord(reqForm.getPoolNos(), reqForm.getDate()[0], reqForm.getDate()[1],reqForm.getUserId()));
    }

    @PostMapping("/delete")
    public R deleteImmunizationRecord(@RequestBody Immunization immunization){
        boolean delete = immunizationService.deleteImmunizationRecord(immunization);
        if (!delete){
            return R.error("删除失败！");
        }
        return R.success("删除成功！");
    }
    @PostMapping("/add")
    public R addImmunizationRecord(@RequestBody Immunization immunization) {
        return immunizationService.add(immunization);
    }

    @PostMapping("/update")
    public R updateImmunizationRecord(@RequestBody Immunization immunization) {
        return R.success(immunizationService.update(immunization));
    }
}
